{include file="public/header"}
<div class="layui-fluid">
    <div class="layui-card">


        <div class="layui-card-body">
<!--            <div style="padding-bottom: 10px;">-->
<!--                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>-->
<!--            </div>-->

            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" data-type="edit"><i-->
<!--                        class="layui-icon layui-icon-edit"></i>编辑</a>-->
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="goumaimoney" data-type="goumaimoney"><i
                        class="layui-icon layui-icon-edit"></i>云尚积分记录</a>
<!--                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i-->
<!--                        class="layui-icon layui-icon-delete"></i>删除</a>-->
            </script>
        </div>
    </div>
</div>

<script src="__ADMIN__/layuiadmin/layui/layui.js"></script>
<script>
    layui.use(['table', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , laydate = layui.laydate;

        $(this).removeAttr("lay-key");//时间框一点就消失处理
        //日期范围
        laydate.render({
            elem: '#test-range'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            ,range: '-'//['#startDate1', '#endDate']
            // ,show: true //直接显示
            // ,format: 'yyyy-MM-dd'
            // ,value: '2018-08-18 - 2018-08-19'
            // ,trigger:'click'
            // ,type: 'date'
        });

        //日期时间选择器
        // laydate.render({
        //     elem: '#test5'
        //     ,type: 'datetime'
        // });

        table.render({
            elem: '#LAY-user-manage'
            , url: "{:url($module . '/index')}"
            , method: 'Post'
            , limit: '{$pageSize}'
            , cols: [[
                {field: 'id', title: 'ID', sort: true}
                , {field: 'key', title: '健名'}
                , {field: 'value', title: '健值', sort: true}
                , {
                    field: 'value', title: '是否开启', align: 'center', templet: function (d) {
                        if (d.value == 'on') {
                            return '<div><input type="checkbox" value="' + d.id + '" checked name="value" lay-skin="switch" lay-text="开启|关闭" lay-filter="value"></div>';
                        } else {
                            return '<div><input type="checkbox" value="' + d.id + '" name="value" lay-skin="switch" lay-text="开启|关闭" lay-filter="value"></div>'
                        }
                    }
                }
                // , {fixed: 'right', title: '操作', toolbar: '#table-useradmin-webuser', width: 200}
            ]]
            , page: true
        });

        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-user-manage', {
                where: field
            });
        });

        //上架开启与否
        form.on('switch(value)', function (data) {
            console.log(data.value);
            $.ajax({
                url: "{:url($module . '/value')}",
                data: {id: data.value, status: data.elem.checked},
                type: "Post",
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.status) {
                        layer.msg(data.msg);
                        table.reload('LAY-user-manage'); //数据刷新
                    } else {
                        layer.msg(data.msg);
                    }
                },
                error: function (data) {
                    $.messager.alert('错误', data.msg);
                }
            });
        });

    });
</script>
{include file="public/footer"}
